package com.heima.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.wemedia.dto.WmMaterialDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.wemedia.service.IWmMaterialService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2021-05-20
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController{

    @Autowired
    private IWmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    @ApiOperation(value = "图片上传", notes = "author:mcm")
    public ResponseResult upload(MultipartFile file) throws Exception {
        return wmMaterialService.upload(file);
    }

    @PostMapping("list")
    @ApiOperation(value = "查询图片列表", notes = "author:mcm")
    public ResponseResult findListByCollection(@RequestBody WmMaterialDto dto){
        return wmMaterialService.findListByCollection(dto);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除图片", notes = "author:mcm")
    public ResponseResult deletePicture(@PathVariable Integer id){
        return wmMaterialService.deletePicture(id);
    }

    @PutMapping("cancel_collect/{id}")
    @ApiOperation(value = "取消收藏", notes = "author:mcm")
    public ResponseResult cancelCollect(@PathVariable Integer id){
        return wmMaterialService.isCollect(id,0);
    }

    @PutMapping("collect/{id}")
    @ApiOperation(value = "收藏", notes = "author:mcm")
    public ResponseResult Collect(@PathVariable Integer id){
        return wmMaterialService.isCollect(id,1);
    }
}
